<template>
  <el-dialog title="添加字典" :visible.sync="dialogVisible" width="30%" :append-to-body="true">
    <el-form ref="addForm" :model="form" :rules="rules" label-width="80px">
      <el-form-item label="流程ID" prop="value">
        <el-input v-model="form.value"></el-input>
      </el-form-item>
      <el-form-item label="流程名称" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
       <el-form-item label="部署ID" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
       <el-form-item label="key" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
       <el-form-item label="版本" prop="note">
        <el-input v-model="form.note"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('addForm')">保存</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
import { baseUrl } from "@/config/env";
const urls = {
  // checkField: baseUrl + "/backletter/common/check_unique", // 验证编码唯一性
  save: baseUrl + "/dict/sys-dict/add",
  list: baseUrl + "/dict/sys-dict/list"
};
export default {
  data() {
    return {
      dialogVisible: false,
      data: [],
      form: {
        value: null,
        note: null,
        typeCode:null
      },
      formInline : {
        
      },
      rules: {
        uname: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          {
            // validator: (rule, value, callback) => {
            //   axios
            //     .get(urls.checkField, {
            //       params: { table: "t_user", field: "uname", value: value }
            //     })
            //     .then(res => {
            //       if (res.data.result) {
            //         callback("用户名必须唯一");
            //       } else {
            //         callback();
            //       }
            //     });
            // },
            trigger: "blur"
          }
        ],
        // name: [{ required: true, message: "请输入用户姓名", trigger: "blur" }],
        pwd: [{ required: true, message: "请输入登录密码", trigger: "blur" }]
      }
    };
  },
  components: {},
  methods: {
    show(typeCode) {
      console.log(typeCode)
      this.form.typeCode = typeCode;
      this.dialogVisible = true;
      if (this.$refs["addForm"]) {
        this.$refs["addForm"].resetFields();
      }
    },
    onSubmit(formName) {
      console.log(formName)
      this.$refs[formName].validate(valid => {
        if (valid) {
          if(!this.form.typeCode) {
            this.$message({
              message : "请先选择字典表类型",
              type :　"warning"
            })
          }else {
            axios.post(urls.save, this.form).then(res => {
              this.$message(res.data.result);
              this.dialogVisible = false;
              this.$emit("refresh");
            });
          }
         
        }
        return false;
      });
    },
    fetch() {
      axios.post(urls.list,{status : 0}).then(res => {
        this.data = res.data.result.records;
      });
    }
  }
};
</script>